<template>
  <div class="statistic-card">
    <div class="statistic">
      <div>
        <span class="value">{{ statistic.value }}</span>
        <span class="suffix">{{ statistic.suffix }}</span>
      </div>
      <slot name="description">
        <div v-if="statistic.trend && statistic.subValue" class="description">
          <i class="el-icon-top" v-if="statistic.trend === 'up'"></i>
          <i class="el-icon-bottom" v-else></i>
          <span>{{ statistic.subValue }}</span>
        </div>
      </slot>
    </div>
    <div :class="['title', titleStyle]">{{ title }}</div>
  </div>
</template>

<script>
import { defineComponent } from "vue";
export default defineComponent({
  name: "StatisticCard",
  props: {
    noStyle: {
      // 去除默认样式
      type: Boolean,
      default: false,
    },
    titleStyle: {
      type: Object,
      default: () => ({}),
    },
    title: String,
    statistic: {
      type: Object,
      default: () => ({
        value: 0,
        suffix: "",
        trend: "",
        subValue: "",
      }),
    },
  },
});
</script>

<style lang="scss" scoped>
.statistic-card {
  display: grid;
  place-content: center;
  grid-template-rows: 1fr 1fr;
  padding: 15px 0;
  background: linear-gradient(
    0deg,
    rgba(122, 138, 172, 0.8),
    rgba(0, 7, 58, 0.8),
    rgba(0, 7, 58, 0.8),
    rgba(162, 180, 201, 0.8)
  );
  border: 1px solid #4b6d86;
  opacity: 0.6;
  border-radius: 30px;
  .title {
    font-size: 21px;
    font-weight: 400;
    color: #ffffff;
    line-height: 42px;
    text-align: left;
  }
  .statistic {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: end;
    justify-content: space-between;
    .value,
    .suffix,
    .description {
      font-size: 42px;
      font-weight: bold;
      color: #add8fc;
      line-height: 42px;
    }
    .suffix {
      font-size: 19px;
    }
    .description {
      font-size: 19px;
      text-align: right;
      color: #1ae249;
    }
  }
}
</style>
